<template>
  <dl>
    <dd>
      <div>
        <span class="tit">发布时间：</span>
        <el-select v-model="form.article_year" placeholder="请选择">
          <el-option
            v-for="item in option.article_year"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
      <div>
        <span class="tit">媒体：</span>
        <el-select v-model="form.medal" placeholder="请选择">
          <el-option
            v-for="item in option.medal"
            :key="item.key"
            :label="item.label"
            :value="item.key">
          </el-option>
        </el-select>
      </div>
    </dd>
    <dd>
      <span class="tit">机构：</span>
      <p class="cont">
        <span v-for="(item, index) in option.organ" :key="index" :class="{active: form.organ === item.key}" @click="handleChangeItem('organ', item)">{{item.key}}</span>
      </p>
    </dd>
    <dd>
      <span class="tit">关键字：</span>
      <p class="cont">
        <span v-for="(item, index) in option.keywords" :key="index" :class="{active: form.keywords === item.key}" @click="handleChangeItem('keywords', item)">{{item.key}}</span>
      </p>
    </dd>
  </dl>
</template>

<script>
export default {
  data() {
    return {
      form: {
        article_year: '全部', // 发布时间
        medal: '全部', // 媒体
        organ: '全部', // 机构
        keywords: '全部', // 关键字
      },
      option: {
        article_year: [],
        medal: [],
        organ: [],
        keywords: []
      },
    }
  },
  methods: {
    init(agg) {
      // 发布时间
      let article_year = [{key: '全部'}]
      article_year = [
        ...article_year,
        ...agg.article_year.map(v => {
          return {
            label: moment(v.key).format('YYYY'),
            key: v.key,
            doc_count: v.doc_count
          }
        })
      ]
      this.$set(this.option, 'article_year', article_year)
      // 媒体
      this.$set(this.option, 'medal', [{key: '全部'}, ...agg.medal])
      // 机构
      this.$set(this.option, 'organ', [{key: '全部'}, ...agg.organ])
      // 关键字
      this.$set(this.option, 'keywords', [{key: '全部'}, ...agg.keywords])
    },
    handleChangeItem(param, item) {
      this.$set(this.form, param, item.key)
    },
    reset() {
      this.form = {
        article_year: '全部', // 发布时间
        medal: '全部', // 媒体
        organ: '全部', // 机构
        keywords: '全部', // 关键字
      }
    }
  },
  watch: {
    form: {
      handler(newVal, oldVal) {
        this.$emit('getParams', this.form)
      },
      deep: true
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
</style>